Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(imt): add rust implementation of imt #134

Merged
merged 7 commits into from
Jul 11, 2024

Conversation

Arch0125
Copy link
Contributor

Description

This PR adds Rust implmentation of IMT, aligned with the current TS version, with the following methods included insert/update/delete/create-proof/verify-proof

Related Issue

Resolves #133

Does this introduce a breaking change?

  • Yes
  • No

Other information

Test coverage

  • Test New IMT Instance

    • Description: Ensure that a new IMT instance is created successfully.
  • Test Leaf Insertion

    • Description: Check if new leaves can be inserted into the tree.
  • Test Leaf Deletion

    • Description: Test the deletion functionality of a leaf in the tree.
  • Test Leaf Update

    • Description: Ensure that a leaf in the tree can be updated correctly.
  • Test Create and Verify Proof

    • Description: Create a Merkle proof for a leaf and verify its correctness.
  • Should Not Initialize with Too Many Leaves

    • Description: The tree should not initialize if the number of leaves exceeds arity ^ depth.
  • Should Not Insert in Full Tree

    • Description: Test that leaves cannot be inserted into a full tree.
  • Should Not Delete Nonexistent Leaf

    • Description: Ensure that attempting to delete a nonexistent leaf results in an error.

@cedoor cedoor requested review from cedoor, 0xjei and vplasencia January 30, 2024 10:23
@cedoor cedoor requested a review from curryrasul January 30, 2024 22:43
packages/imt-rs/src/main.rs Outdated Show resolved Hide resolved
packages/imt-rs/src/lib.rs Outdated Show resolved Hide resolved
packages/imt-rs/src/lib.rs Outdated Show resolved Hide resolved
packages/imt-rs/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest minor changes in the current implementation (I showed few directly). For that I'd recommend using Clippy tool. It's basically a linter, that shows how you can fix/change stuff to follow Rust convention of code. You should also use cargo-fmt tool, if you don't do that.

But overall, Is this implementation follows TS implementation fully? I mean not for API but for how is everything implemented inside.
Cause I'd store the tree not as a Vector of Vectors, but for example as a HashMap, where key is a tuple (depth, position) and value is a following leaf/node. Also we don't need to really initialize all tree in the new function, etc. I'd suggest to check how it's done in pmtree .
If you don't want to change the core structure - then everything's good, except minor fixes I mentioned earlier.
Thanks for attention!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking at the pmtree implementation you mentioned here, do you think this is still valuable as zk-kit.rust package? @curryrasul

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@0xjei, chatted about that with @curryrasul. We're going to add it to the zk-kit.rust repo as the first package :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sweet, tysm for the reply @cedoor

@cedoor
Copy link
Member

cedoor commented Jun 24, 2024

Hey @Arch0125, do you think you'll have time to work on the remaining minor changes?

We're planning to create a ZK-Kit repo for Rust and it would be nice to have this implementation there :)

@Arch0125
Copy link
Contributor Author

Hey @cedoor, yeah ill get done with the minor changes mostly by EOD, or by earlier tomorrow.
It kinda slipped out of my mind, got busy with some stuff at work, apologies for that

@cedoor
Copy link
Member

cedoor commented Jun 26, 2024

@Arch0125 no worries :) Thanks for your quick response!

Copy link
Member

@0xjei 0xjei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @Arch0125 tysm for your work here. I avoided some comments as they were redundant from @curryrasul's review.

In any case, regardless of the design of the solution, I see that the lib.rs is a bit too loaded. It would be nice to have something like:

// this is lib.rs.

pub mod imt;
pub mod hash;

by moving the necessary code into imt.rs and hash.rs respectively.

would love to hear your thoughts here as well @curryrasul

packages/imt-rs/src/lib.rs Outdated Show resolved Hide resolved
packages/imt-rs/src/lib.rs Outdated Show resolved Hide resolved
packages/imt-rs/src/lib.rs Outdated Show resolved Hide resolved
packages/imt-rs/src/lib.rs Outdated Show resolved Hide resolved
packages/imt-rs/src/lib.rs Outdated Show resolved Hide resolved
@Arch0125 Arch0125 requested a review from sripwoud as a code owner June 29, 2024 21:17
@Arch0125
Copy link
Contributor Author

Updating the code structure in the next commit as mentioned by @0xjei

Copy link
Member

@0xjei 0xjei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, tysm @Arch0125

@cedoor
Copy link
Member

cedoor commented Jul 10, 2024

@Arch0125 This PR should be ready right? Could you solve the conflicts?

@Arch0125
Copy link
Contributor Author

Yep solving the conflicts asap

@Arch0125
Copy link
Contributor Author

@cedoor ive fixed the remaining issues that came up after the merge

@cedoor cedoor merged commit 2aa5c8e into privacy-scaling-explorations:main Jul 11, 2024
2 checks passed
Copy link

gitpoap-bot bot commented Jul 11, 2024

Congrats, your important contribution to this open-source project has earned you a GitPOAP!

GitPOAP: 2024 ZK-KIT Contributor:

GitPOAP: 2024 ZK-KIT Contributor GitPOAP Badge

Head to gitpoap.io & connect your GitHub account to mint!

Learn more about GitPOAPs here.

@cedoor
Copy link
Member

cedoor commented Jul 11, 2024

@Arch0125 Thank you so much for this PR! As a second step, we need to move this crate to the zk-kit.rust repo. Would you like to do it yourself?

@Arch0125
Copy link
Contributor Author

Arch0125 commented Jul 11, 2024

@cedoor Yeah sure, ill take it up, can you assign it there ?

@cedoor
Copy link
Member

cedoor commented Jul 11, 2024

@cedoor Yeah sure, ill take it up, can you assign it there ?

Sure, here: privacy-scaling-explorations/zk-kit.rust#3. Can you add a comment there?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build a Rust implementation of the IMTs
4 participants